(function () {
	const officeCode = {};

	const categoryMap = {
		silly_reimbursement: {
			category: 'silly_reimbursement',
			name: 'SILLY报销申请',
			modelUrl: '/reimbursement/',
			addFormUrl: '/reimbursement/v1/form-add.html'
		}
	}

	window.myConst = {
		YESORNO: {YES: '1', NO: '0'},
		officeCode: officeCode,
		categoryMap: categoryMap
	}
}());

/**
 * [userUtil] 当前人工具
 */
(function () {
	let userKey = "common-user-util";

	function getUser() {
		let json = localStorage.getItem(userKey);
		return JSON.parse(json);
	}

	function isAdmin() {
		return getUser().admin;
	}

	function getUserId() {
		return getUser().id;
	}

	function getUserName() {
		return getUser().name;
	}

	function getOffice() {
		return getUser().office;
	}

	function getOfficeId() {
		return !!getOffice() ? getOffice().id : null;
	}

	function getOfficeName() {
		return !!getOffice() ? getOffice().name : null;
	}

	function hasPermission(name) {
		let user = getUser();
		if (isAdmin()) {
			return true;
		}
		return user.permissions && user.permissions.indexOf(name) >= 0;
	}

	function setUser(user) {
		let json = JSON.stringify(user);
		localStorage.setItem(userKey, json);
	}

	function init() {
		setUser({
			id: '1',
			admin: true,
			name: 'admin',
			office: {
				id: '100',
				name: '管理部'
			}
		});
	}


	let userUtil = {
		isAdmin,
		getUser,
		getUserId,
		getUserName,
		getOffice,
		getOfficeId,
		getOfficeName,
		hasPermission,
		setUser
	};

	if (!window.userUtil) {
		init();
		window.userUtil = userUtil;
	}

}());

/**
 * [dateUtil] 日期格式化工具
 */
(function () {

	function format(date, fmt) {
		if (!fmt) {
			fmt = 'yyyy-MM-dd hh:mm:ss';
		}
		if (/(y+)/.test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
		}

		let o = {
			'M+': date.getMonth() + 1,
			'd+': date.getDate(),
			'h+': date.getHours(),
			'm+': date.getMinutes(),
			's+': date.getSeconds()
		};
		for (let k in o) {
			if (new RegExp(`(${k})`).test(fmt)) {
				let str = o[k] + '';
				fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
			}
		}
		return fmt
	}

	function padLeftZero(str) {
		return ('00' + str).substr(str.length)
	}

	function timeShow(timer) {
		if (!timer) {
			return '';
		}
		timer = timer / 1000;
		let tips = '';
		switch (true) {
			case timer < 60:
				tips = parseInt(timer) + '秒';
				break;
			case timer >= 60 && timer < 3600:
				tips = parseInt(timer / 60) + '分钟';
				break;
			case timer >= 3600 && timer < 86400:
				tips = parseInt(timer / 3600) + '小时';
				break;
			case timer >= 86400 && timer < 2592000:
				tips = parseInt(timer / 86400) + '天';
				break;
			default:
				if (timer >= 2592000 && timer < 365 * 86400) {
					tips = parseInt(timer / (86400 * 30)) + '个月';
				} else {
					tips = parseInt(timer / (86400 * 365)) + '年';
				}
		}
		return tips;
	}


	if (!window.dateUtil) {
		window.dateUtil = {};
	}

	window.dateUtil.format = format;
	window.dateUtil.timeShow = timeShow;

}());

/**
 * [myUtil.getUuid] 我的工具类
 */
(function () {

	let loadFromLock = false;
	let loadFromLockFuncArr = [];

	function getUuid() {
		let s = [];
		let hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for (let i = 0; i < 36; i++) {
			s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
		}
		return s.join("")
	}

	function createQueryVariable(variableObj) {
		let variable = Qs.stringify(variableObj, {allowDots: true});
		if (variable) {
			variable = "?" + variable;
		}
		return variable;
	}

	function getQueryVariable(variable) {
		let strings = window.location.href.split("?");
		if (strings.length === 2) {
			let query = strings[1];
			let vars = query.split("&");
			for (let i = 0; i < vars.length; i++) {
				let pair = vars[i].split("=");
				if (pair[0] === variable) {
					return pair[1];
				}
			}
		}
		return (false);
	}

	function loadForm({vue, baseUrl, url, thenFunc, catchFunc, el, $dom, useTempDom}) {
		if (baseUrl === undefined || baseUrl === null) {
			baseUrl = my.base;
		}
		my.http.get(baseUrl + url).then(function (data) {
			if (el) {
				$dom = $(el)
			}

			if (useTempDom && !$dom) {
				// 在Body 追加创建一个 Dom元素
				$dom = $('<div></div>').appendTo("body");
			}

			if (!$dom) {
				$dom = $("#myQEditDivId");
			}
			if ($dom.length === 0) {
				// 在Body 追加创建一个 Dom元素
				if ($('.page-content-area').length > 0) {
					$dom = $('<div id="myQEditDivId"></div>').appendTo(".page-content-area");
				} else {
					$dom = $('<div id="myQEditDivId"></div>').appendTo("body");
				}
			}

			loadFromLockFuncArr.push(function () {
				$dom.html(data);

				let myVue = myUtil.formVue.pop();
				if (useTempDom && myVue) {
					myVue.$tempDom = $dom;
				}
				thenFunc(myVue);
			});

			if (loadFromLock) {
				return;
			}

			loadFromLock = true;

			while (loadFromLockFuncArr.length > 0) {
				let loadFromLockFunc = loadFromLockFuncArr.pop();
				loadFromLockFunc();
			}

			loadFromLock = false;
		}).catch(function (err) {
			if (catchFunc) {
				catchFunc(err)
			} else {
				if (vue) {
					vue.$notify({
						title: '失败',
						message: err,
						type: 'warning'
					});
				}
			}
		});
	}

	let formVue = (function () {
		let formArr = [];
		let formStack = [];
		return {
			all() {
				return formArr;
			},
			get() {
				if (formArr.length === 0) {
					return null;
				}
				return formArr[formArr.length - 1];
			},
			push(data) {
				formStack.push(data);
				let number = formArr.indexOf(data);
				if (number === -1) {
					formArr.push(data);
				}
			},
			remove(data) {
				let number = formArr.indexOf(data);
				if (number >= 0) {
					formArr.splice(number, 1);
				}
			},
			pop() {
				return formStack.pop()
			}
		}
	})();

	function copyObj(obj) {
		if (obj === undefined || obj === null) {
			return null;
		}
		return JSON.parse(JSON.stringify(obj))
	}

	function copyNotEmptyObj(obj) {
		let cObj = copyObj(obj);
		for (let k in cObj) {
			if (cObj.hasOwnProperty(k) && !cObj[k]) {
				delete cObj[k];
			}
		}
		return cObj;
	}

	function copyNotEmptyArr(arr) {
		let cArr = copyObj(arr);
		for (let i = 0; i < cArr.length; i++) {
			if (cArr[i] instanceof Array) {
				cArr[i] = copyNotEmptyArr(cArr[i])
			} else {
				cArr[i] = copyNotEmptyObj(cArr[i])
			}
		}
		return cArr;
	}

	function copyNotEmpty(obj) {
		if (obj instanceof Array) {
			return copyNotEmptyArr(obj);
		} else {
			return copyNotEmptyObj(obj);
		}
	}

	function mergeVueData(vue, source, target, otherNotSet) {
		for (let dataKey in target) {
			if (target.hasOwnProperty(dataKey)) {
				let setFlag = false;
				for (let formKey in source) {
					if (source.hasOwnProperty(formKey)) {
						if (formKey === dataKey && target[dataKey]) {
							vue.$set(source, formKey, target[dataKey]);
							setFlag = true;
							break;
						}
					}
				}
				if (!otherNotSet && !setFlag) {
					vue.$set(source, dataKey, target[dataKey]);
				}
			}
		}
	}

	function isEqual(obj1, obj2, ignoreFields) {
		// 判断是否空值， 若 obj1, obj2 都为空则两者相等
		if ((obj1 === null || obj1 === undefined || obj1 === '')
			&& (obj2 === null || obj2 === undefined || obj2 === '')) {
			return true;
		}
		// 判断引用或值是否相等
		if (obj1 == obj2) {
			return true;
		}

		// 若是数值 直接返回比较值
		if (!isNaN(obj1) && !isNaN(obj2)) {
			return obj1 === obj2;
		}

		// 直接转字符串
		let s1 = JSON.stringify(obj1);
		let s2 = JSON.stringify(obj2);
		// JSON序列化之后判断是否相等
		if (s1 === s2) {
			return true;
		}

		// 判断是否是字符串， 若是字符串，上一步序列化之后不相等，那就不相等了
		if (typeof obj1 === 'string' || typeof obj2 === 'string') {
			return false;
		}

		// 判断是否是数组
		if (obj1 instanceof Array || obj2 instanceof Array) {
			if (obj1 instanceof Array && obj2 instanceof Array) {
				// 判断长度是否一致
				if (obj1.length !== obj2.length) {
					return false;
				}

				// 已做过比较并匹配到相等的index
				let usedArr = [];
				for (let i = 0; i < obj1.length; i++) {
					let eqIndexFlag = false;
					for (let j = 0; j < obj2.length; j++) {
						if (usedArr.indexOf(j) >= 0) {
							continue;
						}
						// 一个个属性进行判断
						let flag = isEqual(obj1[i], obj2[j], ignoreFields);
						if (flag) {
							// 此index找到相等的数据
							usedArr.push(j)
							eqIndexFlag = true;
							break;
						}
					}
					if (!eqIndexFlag) {
						// 此位置的值没有找到相等的，整个数组不相等
						return false;
					}
				}
				return true;
			} else {
				// 类型不一致
				return false;
			}
		}

		// JSON解析获取新的对象
		let cs1 = JSON.parse(s1);
		let cs2 = JSON.parse(s2);
		if (ignoreFields) {
			// 删除对象忽略的参数
			for (let i = 0; i < ignoreFields.length; i++) {
				let ignoreField = ignoreFields[i];
				delete cs1[ignoreField];
				delete cs2[ignoreField];
			}
		}

		// 获取当前对象拥有的属性值
		let cs1PropertyNames = Object.getOwnPropertyNames(cs1);
		let cs2PropertyNames = Object.getOwnPropertyNames(cs2);
		if (cs1PropertyNames.length !== cs2PropertyNames.length) {
			return false;
		}


		for (let i = 0; i < cs1PropertyNames.length; i++) {
			let propertyName = cs1PropertyNames[i];
			// 判断对象参数是否一致
			if (cs2PropertyNames.indexOf(propertyName) < 0) {
				// cs1 cs2 拥有不同参数属性
				return false;
			}

			// 递归判断单个属性
			let flag = isEqual(cs1[propertyName], cs2[propertyName], ignoreFields);
			if (!flag) {
				// cs1 cs2 的[PropertyName] 值 不相等
				return false;
			}
		}
		// 相等
		return true;
	}

	if (!window.myUtil) {
		window.myUtil = {};
	}

	window.myUtil.getUuid = getUuid;
	window.myUtil.createQueryVariable = createQueryVariable;
	window.myUtil.getQueryVariable = getQueryVariable;
	window.myUtil.loadForm = loadForm;
	window.myUtil.formVue = formVue;
	window.myUtil.copyObj = copyObj;
	window.myUtil.copyNotEmptyObj = copyNotEmptyObj;
	window.myUtil.copyNotEmptyArr = copyNotEmptyArr;
	window.myUtil.copyNotEmpty = copyNotEmpty;
	window.myUtil.mergeVueData = mergeVueData;
	window.myUtil.isEqual = isEqual;

}());


function getDiagWidth() {
	let val = document.body.clientWidth;
	let dialogWidth = "";
	if (val < 768) {
		dialogWidth = '100%'
	} else if (val < 1200) {
		dialogWidth = '80%'
	} else {
		dialogWidth = '70%'
	}
	return dialogWidth;
}

function isMobile() {
	let w = document.body.clientWidth;
	let h = document.body.clientHeight;
	return (w < 768 || h < 400);
}


let DialogVue = Vue.extend({
	el: '#form',
	i18n,
	data() {
		return {
			disabled: false,
			loading: false,
			// 弹出框显示标识
			dialogVisible: false,
			// 弹出框宽度
			dialogWidth: '70%',
			finalWidth: null,
			// 是否全屏展示
			fullscreen: false,
			$tempDom: false,
			form: {},
			rowData: {},
			changeDialogVisibleFunc: function (v, rowData) {
			}
		};
	},
	watch: {
		dialogVisible(v) {
			if (v) {
				myUtil.formVue.push(this);
			} else {
				myUtil.formVue.remove(this);
				if (this.$tempDom) {
					this.$tempDom.remove();
				}
			}
			this.changeDialogVisible(v);
		}
	},
	mounted() {
		let that = this;
		window.onresize = function () {
			that.setDialog()
		}
	},
	methods: {
		changeDialogVisible(v) {
			if (this.changeDialogVisibleFunc instanceof Function) {
				this.changeDialogVisibleFunc(v, this.rowData);
			}
		},
		open(obj) {
			this.init(obj);
			this.$nextTick(function () {
				this.dialogVisible = true;
			});
		},
		close() {
			this.beforeClose();
			this.$nextTick(function () {
				this.dialogVisible = false;
			});
		},
		beforeClose() {
		},
		init(obj) {
			if (obj === null || obj === undefined) {
				obj = {};
			}
			this.rowData = obj;
			this.internalInit();
			if (obj.id) {
				this.get(obj.id);
			}
			this.otherInit(obj);
		},
		internalInit() {
		},
		otherInit(obj) {
		},
		setDialog() {
			this.dialogWidth = this.finalWidth || getDiagWidth();
			this.fullscreen = this.fullscreen || isMobile();
		},
		// 根据ID 获取 form 数据
		get(id) {
			let that = this;
			if (!id || !that.getUrl) {
				return new Promise(function () {
				});
			}

			this.loading = true;
			return that.doPromiseGet(id).then(function (data) {
				that.doFormDataMerge(data, id);
				that.loading = false;
			}).then(function () {
				that.afterGet(that);
			});
		},
		doPromiseGet(id) {
			let that = this;
			return my.http.get(that.getUrl, {id: id})
		},
		doFormDataMerge(data, id) {
			let that = this;
			if (data.code === 0 && data.data && Object.keys(data.data).length > 0) {
				myUtil.mergeVueData(that, that.form, data.data);
			}
		},
		// 获取数据之后的回调
		afterGet(that) {
		}
	},
	created() {
		myUtil.formVue.push(this);
		this.setDialog();
	}
});

/**
 * 可保存数据弹窗 Vue
 */
let SaveDataVue = DialogVue.extend({
	el: '#form',
	data() {
		return {
			// 保存按钮加载中 标识
			saveDisabled: false,
			modelUrl: null,
			saveUrl: null,
			getUrl: null,
			rules: [],
			// 保存成功后执行的方法
			successFunc: function () {

			}
		}
	},
	methods: {
		internalInit() {
			if (this.modelUrl) {
				if (!this.saveUrl) {
					this.saveUrl = this.modelUrl + 'save';
				}
			}
		},
		// 表单校验（基于 表单 refs 值）
		checkField() {
			let that = this;
			let count = 0;
			for (let k in that.$refs) {
				if (!that.$refs.hasOwnProperty(k) || !that.$refs[k]) {
					continue;
				}

				if (that.$refs[k].validate) {
					that.$refs[k].validate(function (valid, a) {
						if (!valid) {
							count += Object.getOwnPropertyNames(a).length;
						}
					});
				} else if (that.$refs[k].length) {
					for (let i = 0; i < that.$refs[k].length; i++) {
						if (that.$refs[k][i] && that.$refs[k][i].validate) {
							that.$refs[k][i].validate(function (valid, a) {
								if (!valid) {
									count += Object.getOwnPropertyNames(a).length;
								}
							});
						}
					}
				}
			}

			count = that.otherCheckField(count);

			if (count > 0) {
				that.$notify({
					title: '表单未完成',
					message: '还有 ' + count + ' 项必填项未完成填写',
					type: 'warning'
				});
			}
			return count === 0;
		},
		// 除了默认方式外的表单校验
		otherCheckField(count) {
			return count;
		},
		// 保存方法执行之前的方法
		beforeSave(submit) {

		},
		// 保存方法
		save(submit) {
			let that = this;
			that.beforeSave(submit);
			let passFlag = true;
			if (submit) {
				passFlag = that.checkField();
			}
			if (passFlag) {
				let saveData = that.saveData();
				saveData.submit = submit;
				that.doSave(saveData)
			}
		},
		// 保存的数据获取
		saveData(saveHandlerObj) {
			return this.form;
		},
		// 执行提交数据前的回调
		preSave(saveData) {

		},
		// 执行数据提交
		doSave(saveData) {
			let that = this;
			that.saveDisabled = true;
			that.preSave(saveData);
			my.http.post(that.saveUrl, saveData).then(function (data) {
				if (data.code === 0) {
					that.$notify({
						title: '成功',
						message: '保存成功',
						type: 'success'
					});
					that.dialogVisible = false;
					that.successFunc(data);
				} else {
					that.$notify({
						title: '失败',
						message: data.msg,
						type: 'warning'
					});
				}
				that.saveDisabled = false;
			}).catch(function (err) {
				that.$notify({
					title: '失败',
					message: err,
					type: 'warning'
				});
				that.saveDisabled = false;
			});
		}
	}
})

/**
 * 定义专属 vue
 */
let SillyVue = SaveDataVue.extend({
	el: '#form',
	data() {
		return {
			id: null,
			taskId: null,
			nodeKey: null,
			// 表单数据
			form: {},
			getObj: {},
			categoryMap: null,
			getSillyOptionUrl: '',
			sillyOption: [],
			btnOption: [],
			baseBtnOption: {
				save: {
					type: 'success',
					icon: 'el-icon-check',
				},
				submit: {
					type: 'primary',
					icon: 'el-icon-right',
				},
				flow: {
					type: 'warning',
					icon: 'el-icon-s-custom'
				},
				reject: {
					type: 'danger',
					icon: 'el-icon-back'
				}
			}
		};
	},
	methods: {
		internalInit(obj) {
			this.rowData = obj;
			if (obj.taskId) {
				this.taskId = obj.taskId;
			}
			if (obj.taskObj && !this.nodeKey) {
				this.nodeKey = obj.taskObj.nodeKey;
			}
			if (!this.getUrl) {
				this.getUrl = my.base + '/silly/' + this.categoryMap.category + '/root';
			}
			if (!this.getSillyOptionUrl) {
				this.getSillyOptionUrl = my.base + '/silly/' + this.categoryMap.category + '/option';
			}
			if (!this.saveUrl) {
				if (this.taskId) {
					this.saveUrl = my.base + '/silly/' + this.categoryMap.category + '/saveMap';
				} else {
					this.saveUrl = my.base + '/silly/' + this.categoryMap.category + '/add';
				}
			}
			if (obj.id) {
				this.id = obj.id;
				this.getSillyOption();
				this.get(obj.id, this.nodeKey);
			}
		},
		init(obj) {
			if (!obj) {
				obj = {};
			}
			this.internalInit(obj);

			this.otherInit(obj);
		},
		doFormDataMerge(data) {
			let that = this;
			that.getObj = data;
			if (data.code === 0 && data.data && Object.keys(data.data).length > 0) {
				myUtil.mergeVueData(that, that.form, data.data, true);
			}
		},
		saveData(saveHandlerObj) {
			let copyObj = myUtil.copyObj(this.form);
			copyObj.taskId = this.taskId;
			return copyObj;
		},
		doSave(saveData) {
			let that = this;
			that.saveDisabled = true;
			that.preSave(saveData);
			my.http.postJson(that.saveUrl, saveData)
				.then(function (data) {
					if (data.code === 0) {
						that.$notify({
							title: '成功',
							message: '保存成功',
							type: 'success'
						});
						that.dialogVisible = false;
						that.successFunc(data);
					} else {
						that.$notify({
							title: '失败',
							message: data.msg,
							type: 'warning'
						});
					}
					that.saveDisabled = false;
				}).catch(function (err) {
				that.$notify({
					title: '失败',
					message: err,
					type: 'warning'
				});
				that.saveDisabled = false;
			});
		},
		getSillyOption() {
			let that = this;
			if (!that.rowData.id || !that.rowData.taskId) {
				return;
			}

			my.http.get(that.getSillyOptionUrl, {
				id: that.rowData.id,
				taskId: that.rowData.taskId
			}).then(function (data) {
				that.sillyOption = data.data;
				let btnOption = [];
				for (let i = 0; i < that.sillyOption.length; i++) {
					let item = that.sillyOption[i];
					btnOption.push(Object.assign(that.baseBtnOption[item.key], item))
				}

				that.btnOption = btnOption;
			});
		},
		handleOption(option) {
			let that = this;
			const key = option.key;
			let funcName = 'silly' + key.charAt(0).toUpperCase() + key.slice(1)
			let func = that[funcName];
			if (func instanceof Function) {
				func(option);
			} else {
				alert("未定义此方法" + key);
			}
		},
		sillySave(option) {
			let that = this;
			if (option.url) {
				that.saveUrl = my.base + "/" + option.url;
			}
			that.save(false);
		},
		sillySubmit(option) {
			let that = this;
			if (option.url) {
				that.saveUrl = my.base + "/" + option.url;
			}
			that.save(true);
		},
		sillyFlow(option) {
			let that = this;
			myUtil.loadForm({
				url: "/common/flow-form.html",
				useTempDom: true,
				thenFunc: (formVue) => {
					formVue.open({taskId: that.taskId, option: option});
					formVue.successFunc = function () {
						that.close();
					}
				},
				catchFunc: (res) => {
					that.$notify({
						title: '异常',
						message: res,
						type: 'warning'
					});
				}
			});
		},
		sillyReject(option) {
			let that = this;
			myUtil.loadForm({
				url: "/common/reject-form.html",
				useTempDom: true,
				thenFunc: (formVue) => {
					formVue.open({taskId: that.taskId, option: option});
					formVue.successFunc = function () {
						that.close();
					}
				},
				catchFunc: (res) => {
					that.$notify({
						title: '异常',
						message: res,
						type: 'warning'
					});
				}
			});
		}
	}
});

/**
 * 工作流专用 SillyIndexVue
 */
let BaseIndexVue = Vue.extend({
	el: '#index',
	i18n,
	data: function () {
		return {
			// 业务分类（必需）
			categoryMap: {},
			// 当前响应的 tab 页名称
			activeTab: 'todo',
			// 当前查询对象
			searchForm: {},
			// 表格对象
			tableData: {
				todo: {
					list: [],
					pageSize: 20,
					pageNo: 1,
					total: 0,
					loading: false,
					showSearch: false,
					baseSearchForm: {},
					searchForm: {},
					pageUrl: null,
					delUrl: null,
					handleUrl: null,
				},
				history: {
					list: [],
					pageSize: 20,
					pageNo: 1,
					total: 0,
					loading: false,
					showSearch: false,
					baseSearchForm: {},
					searchForm: {},
					pageUrl: null,
					delUrl: null,
					handleUrl: null,
				},
				query: {
					list: [],
					pageSize: 20,
					pageNo: 1,
					total: 0,
					loading: false,
					showSearch: false,
					baseSearchForm: {},
					searchForm: {},
					pageUrl: null,
					delUrl: null,
					handleUrl: null,
				}
			}
		}
	},
	watch: {
		activeTab(v) {
			this.loadTableData();
		}
	},
	methods: {
		init() {
			let that = this;
			that.otherInit();
			Vue.nextTick(function () {
				that.loadTableData()
			})
		},
		otherInit() {
		},
		query: function () {
			this.loadTableData();
		},
		reset: function () {
			let that = this;
			let active = that.tableData[that.activeTab];
			active.searchForm = myUtil.copyObj(active.baseSearchForm);
			this.query();
		},
		indexMethod(index) {
			let that = this;
			let active = that.tableData[that.activeTab];
			return 1 + index + (active.pageSize * (active.pageNo - 1));
		},
		loadTableData() {
			let that = this;
			let active = that.tableData[that.activeTab];
			if (!active.pageUrl) {
				active.pageUrl = my.base + '/silly/' + that.categoryMap.category + '/' + that.activeTab;
			}
			active.loading = true;
			let search = myUtil.copyObj(active.searchForm);
			search.pageNo = active.pageNo;
			search.pageSize = active.pageSize;
			my.http.get(active.pageUrl, search).then(function (res) {
				if (res.code === 0) {
					active.list = res.list;
					active.total = res.total;
				}
				active.loading = false;
			}).catch(function (res) {
				active.loading = false;
			});
		},
		deleteRow: function (row) {
			let that = this;
			that.$confirm('此操作将永久删除所选内容, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(function () {
				let active = that.tableData[that.activeTab];
				if (!active.delUrl) {
					active.delUrl = my.base + '/silly/' + that.categoryMap.category + '/delete/';
				}
				my.http.post(active.delUrl + row.id).then(function (data) {
					if (data.code === 0) {
						that.$notify({
							type: 'success',
							message: '删除成功!'
						});
						that.loadTableData();
					} else {
						that.$notify({
							title: '失败',
							message: data.msg,
							type: 'warning'
						});
					}
				});
			});
		},
		add: function () {
			let that = this;
			myUtil.loadForm({
				url: that.categoryMap.addFormUrl,
				thenFunc: (formVue) => {
					formVue.open();
					formVue.changeDialogVisibleFunc = function (v) {
						if (!v) {
							that.loadTableData();
						}
					};
				},
				catchFunc: (res) => {
					that.$notify({
						title: '异常',
						message: res,
						type: 'warning'
					});
				}
			});
		},
		handle: function (row) {
			let that = this;
			let active = that.tableData[that.activeTab];
			let formUrl = active.handleUrl;
			if (!formUrl) {
				formUrl = that.categoryMap.modelUrl + row.processVersion.toLowerCase() + '/form-' + row.taskObj.nodeKey.toLowerCase() + '.html';
			}
			myUtil.loadForm({
				url: formUrl,
				thenFunc: (formVue) => {
					formVue.open(row);
					formVue.changeDialogVisibleFunc = function (v) {
						if (!v) {
							that.loadTableData();
						}
					};
				},
				catchFunc: (res) => {
					that.$notify({
						title: '异常',
						message: res,
						type: 'warning'
					});
				}
			});
		},
		detail: function (row) {
			let that = this;
			myUtil.loadForm({
				url: that.categoryMap.modelUrl + row.processVersion.toLowerCase() + '/detail.html',
				thenFunc(formVue) {
					formVue.disabled = true;
					formVue.open(row);
				}
			});
		},
	},
	created() {
		this.init();
	}
});


// v-dialog-drag: 弹窗拖拽
DialogVue.directive('dialogDrag', {
	bind(el, binding, vnode, oldVnode) {
		const dialogHeaderEl = el.querySelector('.el-dialog__header');
		const dragDom = el.querySelector('.el-dialog');
		dialogHeaderEl.style.cursor = 'move';

		// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
		const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);

		dialogHeaderEl.onmousedown = function (e) {
			// 鼠标按下，计算当前元素距离可视区的距离
			const disX = e.clientX - dialogHeaderEl.offsetLeft;
			const disY = e.clientY - dialogHeaderEl.offsetTop;

			// 获取到的值带px 正则匹配替换
			let styL, styT;

			// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
			if (sty.left.includes('%')) {
				styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
				styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
			} else {
				styL = +sty.left.replace(/\px/g, '');
				styT = +sty.top.replace(/\px/g, '');
			}

			document.onmousemove = function (e) {
				// 通过事件委托，计算移动的距离
				const l = e.clientX - disX;
				const t = e.clientY - disY;

				// 移动当前元素
				dragDom.style.left = `${l + styL}px`;
				dragDom.style.top = `${t + styT}px`;

				//将此时的位置传出去
				//binding.value({x:e.pageX,y:e.pageY})
			};

			document.onmouseup = function (e) {
				document.onmousemove = null;
				document.onmouseup = null;
			};
		}
	}

});


// v-my-drag: 弹窗拖拽
Vue.directive('myDrag', {
	bind(el, binding, vnode, oldVnode) {
		const dialogHeaderEl = el.querySelector('.my-dialog-header');
		const dragDom = el.querySelector('.my-dialog-dom');
		dialogHeaderEl.style.cursor = 'move';

		// 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
		const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);

		dialogHeaderEl.onmousedown = function (e) {
			// 鼠标按下，计算当前元素距离可视区的距离
			const disX = e.clientX - dialogHeaderEl.offsetLeft;
			const disY = e.clientY - dialogHeaderEl.offsetTop;

			// 获取到的值带px 正则匹配替换
			let styL, styT;

			// 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px
			if (sty.left.includes('%')) {
				styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
				styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
			} else {
				styL = +sty.left.replace(/\px/g, '');
				styT = +sty.top.replace(/\px/g, '');
			}

			document.onmousemove = function (e) {
				// 通过事件委托，计算移动的距离
				const l = e.clientX - disX;
				const t = e.clientY - disY;

				// 移动当前元素
				dragDom.style.left = `${l + styL}px`;
				dragDom.style.top = `${t + styT}px`;

				//将此时的位置传出去
				//binding.value({x:e.pageX,y:e.pageY})
			};

			document.onmouseup = function (e) {
				document.onmousemove = null;
				document.onmouseup = null;
			};
		}
	}

});

